package com.ktwlsoft.archivemanage.controller.customAnalysis;

import com.ktwlsoft.archivemanage.domain.business.businessService.customAnalysis.CustomAnalysisService;
import com.ktwlsoft.archivemanage.payload.Result;
import com.ktwlsoft.archivemanage.payload.ResultType;
import com.ktwlsoft.archivemanage.payload.customAnalysis.CustomAnalysisSaveRequest;
import com.ktwlsoft.archivemanage.payload.customAnalysis.CustomAnalysisUpdateRequest;
import com.ktwlsoft.archivemanage.payload.customAnalysis.GetChartDataRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 自助分析
 *
 * @author zhuhe on 2019/11/27 15:44
 * @version 1.0
 */
@Api(value = "自助分析", description = "自助分析")
@RestController
@RequestMapping("customAnalysis")
public class CustomAnalysisController {

    private final CustomAnalysisService customAnalysisService;

    public CustomAnalysisController(CustomAnalysisService customAnalysisService) {
        this.customAnalysisService = customAnalysisService;
    }

    /**
     * 自助分析列表 on 2019/10/24 17:02
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "自助分析列表", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "findPage")
    public ResponseEntity<?> findPage(@RequestParam(defaultValue = "1") int pn,
                                      @RequestParam(defaultValue = "30") int pageSize,
                                      @ApiParam("关键字") @RequestParam(defaultValue = "", required = false) String keywords,
                                      @ApiParam(name = "field", value = "排序字段") @RequestParam(defaultValue = "", required = false) String field,
                                      @ApiParam(name = "order", value = "排序方式:descend(降序),ascend(升序)") @RequestParam(defaultValue = "", required = false)String order){
        return ResponseEntity.ok(customAnalysisService.findPage(pn,pageSize,keywords,field,order));
    }

    /**
     * 自助分析详情 on 2019/10/24 17:02
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "自助分析详情", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "getDetails")
    public ResponseEntity<?> getDetails(@ApiParam(name = "id", value = "自助分析id") @RequestParam Long id){
        return ResponseEntity.ok(customAnalysisService.getDetails(id));
    }

    /**
     * 删除图表 on 2019/10/24 17:02
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "删除图表", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "deleteChart")
    public ResponseEntity<?> deleteChart(@ApiParam(name = "id", value = "图表id") @RequestParam(defaultValue = "", required = true) Long id){
        return ResponseEntity.ok(customAnalysisService.deleteChart(id));
    }

    /**
     * 图表新增 on 2019/10/28 9:32
     *
     * @param request request
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "图表新增", httpMethod = "POST", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @PostMapping("save")
    public ResponseEntity<?> save(@Valid @RequestBody CustomAnalysisSaveRequest request) {
        return ResponseEntity.ok(customAnalysisService.save(request));
    }

    /**
     * 图表编辑 on 2019/10/28 9:32
     *
     * @param request request
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "图表编辑", httpMethod = "POST", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @PostMapping("modify")
    public ResponseEntity<?> modify(@Valid @RequestBody CustomAnalysisUpdateRequest request) {
        return ResponseEntity.ok(customAnalysisService.modify(request));
    }

    /**
     * 获取图表数据 on 2019/10/24 17:02
     *
     * @return ResponseEntity<?>
     */
    @ApiOperation(value = "获取图表数据", httpMethod = "POST", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @PostMapping(value = "getChartData")
    public ResponseEntity<?> getChartData(@RequestBody GetChartDataRequest request) {
        return ResponseEntity.ok(customAnalysisService.getChartData(request));
    }
}